home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 101 / CD-ROM 101.iso / compl / maya5ple / Install_MayaPLE5_English.exe / Maya / Data1.cab / rigidBodyInterpenetrate.mel < prev    next >
Encoding:
Text File  |  2003-07-17  |  2.8 KB  |  104 lines

  1. // Copyright (C) 1997-2002 Alias|Wavefront,
  2. // a division of Silicon Graphics Limited.
  3. //
  4. // The information in this file is provided for the exclusive use of the
  5. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  6. // and incorporate this code into other products for purposes authorized
  7. // by the Alias|Wavefront license agreement, without fee.
  8. //
  9. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  10. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  11. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  12. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  13. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  14. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. // PERFORMANCE OF THIS SOFTWARE.
  16. //
  17. //
  18. // Alias|Wavefront Script File
  19. // MODIFY THIS AT YOUR OWN RISK
  20. //
  21.  
  22.  
  23. global proc rigidBodyInterpenetrate( int $flag )
  24. //
  25. // Enable the cache for all the selected dynamic objects.
  26. {
  27.     int    $i;
  28.     int    $okToInterpenetrate = 1;
  29.     int    $rigidBodyCount;
  30.     string $rigidSolver;
  31.     string $rigidBodyList[];
  32.     string $selObj[] = `ls -sl`;
  33.  
  34.  
  35.     for ($i = 0; $i < size( $selObj ); $i++)
  36.     {
  37.         string  $leaves[] = `ls -selection -dag -leaf -showType $selObj[$i]`;
  38.  
  39.         // Turn on all the caches for the selected objects.
  40.         //
  41.         for ($j = 0; $j < size( $leaves ); $j += 2)
  42.         {
  43.             if ($leaves[$j+1] == "rigidBody")
  44.             {
  45.                 $rigidBodyList[ $rigidBodyCount ] = $selObj[$i];
  46.                 $rigidBodyCount++;
  47.             }
  48.         }
  49.     }
  50.  
  51.     $rigidBodyCount = size($rigidBodyList);
  52.  
  53.     // First make sure all the selected rigid bodies are in the same
  54.     // solver.
  55.     //
  56.     if ( $rigidBodyCount > 1 )
  57.     {
  58.         $rigidSolver = `rigidBody -q -solver $rigidBodyList[0]`;
  59.  
  60.         for ( $i = 0; $i < $rigidBodyCount; $i++ )
  61.         {
  62.             string $solverName = `rigidBody -q -solver $rigidBodyList[$i]`;
  63.  
  64.             if ( $solverName != $rigidSolver )
  65.             {
  66.                 $okToInterpenetrate = 0;
  67.                 warning ( "All the selected rigid bodies must be in the same solver to set interpenetration/collision." );
  68.                 break;
  69.             }
  70.         }
  71.     }
  72.     else
  73.     {
  74.         $okToInterpenetrate = 0;
  75.         warning ( "At least two rigid bodies must be selected." );
  76.     }
  77.  
  78.     if (  $okToInterpenetrate == 1 )
  79.     {
  80.         string $rigidBodies;
  81.  
  82.         string $rigidSolver = `rigidBody -q -solver $rigidBodyList[0]`;
  83.  
  84.         for ( $i = 0; $i < $rigidBodyCount; $i++ )
  85.         {
  86.             $rigidBodies += $rigidBodyList[$i];
  87.             $rigidBodies += " ";
  88.         }
  89.  
  90.         string $cmd  = "rigidSolver -e ";
  91.         if ( $flag == 0 )
  92.         {
  93.             $cmd = $cmd + "-collide ";
  94.         }
  95.         else
  96.         {
  97.             $cmd = $cmd + "-interpenetrate ";
  98.         }
  99.  
  100.         $cmd = $cmd + $rigidBodies + " " + $rigidSolver;
  101.         evalEcho $cmd;
  102.     }
  103. }
  104.